﻿using System.Data;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using YiTu.DBUtility;

namespace TOUR.SZHOME.DAL
{
    public partial class AlbumDAL
    {
        /// <summary>
        /// 修改排序
        /// </summary>
        /// <param name="id">当前id</param>
        /// <param name="num">当前id排序</param>
        /// <param name="id2">要交换的id</param>
        /// <param name="num2">要交换的id排序</param>        
        /// <returns></returns>
        public static bool OrderUpdate(long id, int num, long id2, int num2)
        {
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                string sql = "update Album set [Order] = @orderNum where [ID]=@ID; update Album set [Order] = @orderNum1 where [ID]=@ID1;";

                using (SqlCommand cmd = new SqlCommand(sql,con))
                {
                    cmd.Parameters.AddWithValue("@ID", id);
                    cmd.Parameters.AddWithValue("@orderNum", num2);
                    cmd.Parameters.AddWithValue("@ID1", id2);
                    cmd.Parameters.AddWithValue("@orderNum1", num);
                    con.Open();
                    bool flag = cmd.ExecuteNonQuery() > 0 ? true :false;
                    con.Close();
                    return flag;
                }
            }
        }
    }
}
